<?php

namespace Models;

use Models\Common\MoneyLogRecord;
use Models\Common\MoneyLogTrait;

class OrderRefund extends Model implements MoneyLogRecord
{
    use MoneyLogTrait;

    protected $_table = 'order_refunds';

	protected $_filter = FALSE;

	protected $_primekey = 'id';

    protected $_has_many = [
        'refunds' => [
            'class' => Refund::Class,
            'foreign' => 'order_refund_id',
        ]
    ];

    protected $_belongs = [
        'user'=>[
			'class' => User::Class,
			'foreign' => 'id',
			'belongs_key' => 'user_id',
		],
        'cashier'=>[
			'class' => Cashier::Class,
			'foreign' => 'id',
			'belongs_key' => 'cashier_id',
		],
        'order' => [
            'class' => Order::Class,
            'foreign' => 'id',
			'belongs_key' => 'order_id',
        ]
    ];

    /* {@inheritDoc} */
	public function getMoneyType()
	{
		return 4;
	}

	public function getMoneyLogData($data = null)
	{
		return [
			'type' => isset($data['type']) ? $data['type'] : $this->getMoneyType(),
			'user_id' => $this['user_id'] ?: 0,
			'cashier_id' => $this['cashier_id'],
			'relation_id' => $this['order_id'],
			'num' => $this['money'],
			'last' => $this['last'],
			'now' => $this['now'],
			'desc' => isset($data['desc']) ? $data['desc'] : '',
			'pay_type' => $this['pay_mode'],
			'from' => isset($data['from']) ? $data['from'] : '',
			'create_time' => date('Y-m-d H:i:s')
		];
	}
}
